﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System;
using System.Linq;

namespace MaiPlanServer.API.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class TestController : ControllerBase
    {
        /// <summary>
        /// 分页获取数据
        /// </summary>
        /// <param name="PageIndex">当前页数</param>
        /// <param name="PageSize">每页显示条数</param>
        /// <param name="TestName">测试模糊搜索</param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult Get(int PageIndex, int PageSize, string TestName)
        {
            try
            {
                var list = new List<string>();
                TestName = TestName ?? "";
                var li = list.Skip(PageSize * (PageIndex - 1)).Take(PageSize).Where(x => x.Contains(TestName)).ToList();

                var count = list.Count(x => x.Contains(TestName));

                return Ok(new { code = 200, msg = "请求成功", count = count, data = li });
            }
            catch (Exception ex)
            {
                return Ok(new { code = -1, msg = "请求失败", count = 0, data = "" });
            }
        }
    }
}
